$(function(){
	var data = {
			url:path+'/repository/stock-in',
			columns: [{
				field: 'checked',
				checkbox: true,
			}, {
				field: 'stockInId',
				visible: false
			}, {
				field: 'stockInInputTime',
				title: '数据录入时间',
				sortable: true
			}, {
				field: 'stockInOrderNumber',
				title: '入库单号'
			}, {
				field: 'stockInExecutor',
				title: '执行人员'
			}, {
				field: 'stockInStatus',
				title: '入库状态',
				formatter: function (value, row, index) {
					
					switch (value){
						case "等待入库":
							return "<span class='layui-badge-rim'>等待入库</span>"
						case "入库中":
							return "<span class='layui-badge layui-bg-blue'>入库中</span>"
						case "入库完成":
							return "<span class='layui-badge layui-bg-green'>入库完成</span>"
						default:
							return "<span class='layui-badge'>非法数据篡改</span>"
					}
					
				}
			}, {
				field: 'stockInRemark',
				title: '备注'
			}],	
			method: 'GET',//请求方式（*）
			contentType : "application/x-www-form-urlencoded;charset='UTF-8'", //加上这个才可以接收到值
			sortable: true,
			sortOrder: "asc",
			search: false,
			exportOptions:{  
			   fileName: '入库信息'+exportDate.toLocaleString(),//文件名称设置  
			   worksheetName: 'sheet1',//表格工作区名称  
			   tableName: '入库信息',
				           ignoreColumn: [0,1],
						   unaffectedColumn:0
			}
	}
	
	var param = [{text:"录入时间",name:"dateScope",type:"text",verify:""},{text:"入库单号",name:"stockInOrderNumber",type:"text",verify:"intNumber"},{text:"执行人员",name:"stockInExecutor",type:"text",verify:"peopleName"},{text:"入库状态",name:"stockInStatus",type:"select",verify:"chineseStr",option:[{key:"等待入库",value:"等待入库"},{key:"入库中",value:"入库中"},{key:"入库完成",value:"入库完成"}]}];
	
	renderTable(cTable,data);
	
	createQueryPanel(param);
	
	//条件查询 日期组建渲染
	laydate.render({
		 elem:  "[name='dateScope']"
		 ,type: 'datetime'
		 ,range: true
	});
	
	form.render();
})

//添加按钮
$("#add_btn").click(function(){
	
	openOperateWindow({
		title: "添加入库单",
		full: true,
		url: "/admin/enterpriseManagement/repositoryManagement/stockIn/stock-in-add.jsp"
	})
})

//删除按钮
$("#remove_btn").click(function(){
	
	//用来存储选中行的id号
	var ids = ''; 

	//获取所有被选中的记录
  var rows = cTable.bootstrapTable('getSelections'); 

	if (rows.length == 0) { //判断是否有选中行
		fixedAlert('最少选中一条记录!',0);
		return;
	}else if(rows[0].stockInStatus == "入库完成") { //判断是否有选中行
		fixedAlert('入库完成的单子不允许删除!',0);
		return;
	}
	
	for (var i = 0; i < rows.length; i++) { //遍历拼接获取到的id号码
	  ids += rows[i].stockInId + ","; 
	}
	
	ids = ids.substring(0, ids.length - 1);
	
	$.ajax({
	   type: 'DELETE',
	   url: path+"/repository/stock-in/"+ids,
	   async: false,
	   contentType: "application/x-www-form-urlencoded;charset='UTF-8'", 
	   beforeSend: function () {
		   layerIndex = layer.load(2);
       },
       statusCode: {
		   200: function() {
			   fixedAlert('删除成功!',1,true); 
			   cTable.bootstrapTable('refresh');//刷新表格
		   },
		   400: function() {
			   fixedAlert('删除失败!',2,false);
		   },
		   500: function() {
			   fixedAlert('服务端繁忙!',2,false);
		   }
	   },
       complete: function(){
    	   layer.close(layerIndex);
       }
	})
})

//修改按钮
$("#modify_btn").click(function(){
	
	openOperateWindow({
		title: "更新入库单",
		isUpdate: true,
		full: true,
		url: "/admin/enterpriseManagement/repositoryManagement/stockIn/stock-in-update.jsp"
	})
})
